<?php

namespace app\api\model;


class IndexList extends BaseModel
{
    //
    protected $table = 'cauth_dish';

    // 读取器调用基类方法处理图片url地址
    public function getDishImagesAttr($value)
    {
        return $this->prefixImages($value);
    }

    // 关联商品图片一对多
    public function dishImg()
    {
        return $this->hasMany('Detail', 'dish_id', 'id');
    }

    // 首页限时促销列表查询
    public static function getTimeLimit()
    {
        $timeLimit = self::where('dish_cate', '=', 1)
            ->with('dishImg')
            ->order('dish_nprice', 'desc')
            ->limit(1)
            ->select();

        return $timeLimit;
    }

    // 首页限量抢购列表查询
    public static function getTimeLimitPay($limit_count)
    {
        $timeLimitPay = self::where('dish_num', '<=', 40)
            ->with('dishImg')
            ->order('dish_nprice', 'desc')
            ->limit($limit_count)
            ->select();

        return $timeLimitPay;
    }

    // 首页特价商品列表
    public static function getDiscountPrice($discount_count)
    {
        $discountPrice = self::where('dish_gprice', '>', 0)
            ->with('dishImg')
            ->order('dish_nprice', 'asc')
            ->limit($discount_count)
            ->select();

        return $discountPrice;
    }

    // 首页推荐列表查询
    public static function getRecommendByCount($recommend_count)
    {
        $recommend = self::order('dish_count', 'desc')->with('dishImg')->limit($recommend_count)->select();

        return $recommend;
    }

    // 首页新鲜食材列表查询
    public static function getFreshByCount($fresh_count)
    {
        $fresh = self::where('dish_cate', '=', 1)
            ->with('dishImg')
            ->order('dish_nprice', 'desc')
            ->limit($fresh_count)
            ->select();

        return $fresh;
    }

    // 首页小吃专属列表查询
    public static function getSnackByCount($snack_count)
    {
        $snack = self::where('dish_cate', '=', 3)
            ->with('dishImg')
            ->order('dish_nprice', 'desc')
            ->limit($snack_count)
            ->select();

        return $snack;
    }

    // 首页粉面特惠列表查询
    public static function getFlourByCount($flour_count)
    {
        $flour = self::where('dish_cate', '=', 2)
            ->with('dishImg')
            ->order('dish_nprice', 'desc')
            ->limit($flour_count)
            ->select();

        return $flour;
    }
}
